#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include "wrap.h"
int main(int argc, char const *argv[])
{
        int fd = Socket(AF_INET,SOCK_DGRAM,0);
        //初始化服务器的ip和端口
        struct sockaddr_in serv;
        memset(&serv,0,sizeof(serv));
        serv.sin_family = AF_INET;
        serv.sin_port = htons(8888);
        inet_pton(AF_INET,"127.0.0.1", &serv.sin_addr.s_addr);
        //通讯
        char buf[1024] = {0};
        while (1){
                fgets(buf,sizeof(buf),stdin);
                //给服务器端发送数据 服务器的ip和地址
                sendto(fd,buf,strlen(buf)+1,0,(struct sockaddr*)&serv,sizeof(serv));
                
                //等待服务器发送数据过来
                int recvlen = recvfrom(fd,buf,sizeof(buf),0,NULL,NULL);
                if(recvlen == -1){
                        perr_exit("recvfrom error");
                }
                printf("recv buf:%s\n",buf);
        }
        Close(fd);
        return 0;
}
